package com.exercise.widgets.recyclerview.nestcardlist.adapter

import com.chad.library.adapter.base.BaseNodeAdapter
import com.chad.library.adapter.base.entity.node.BaseNode
import com.exercise.widgets.recyclerview.nestcardlist.model.BottomDecoration
import com.exercise.widgets.recyclerview.nestcardlist.model.ChildModel
import com.exercise.widgets.recyclerview.nestcardlist.model.DataModel
import com.exercise.widgets.recyclerview.nestcardlist.model.TopDecoration
import com.exercise.widgets.recyclerview.nestcardlist.provider.BottomDecorationProvider
import com.exercise.widgets.recyclerview.nestcardlist.provider.ContentProvider
import com.exercise.widgets.recyclerview.nestcardlist.provider.TitleProvider
import com.exercise.widgets.recyclerview.nestcardlist.provider.TopDecorationProvider

class NestListAdapter : BaseNodeAdapter() {
    init {
        addNodeProvider(TopDecorationProvider(TYPE_TOP))
        addNodeProvider(BottomDecorationProvider(TYPE_BOTTOM))
        addNodeProvider(TitleProvider(TYPE_TITLE))
        addNodeProvider(ContentProvider(TYPE_CHILD))
    }

    override fun getItemType(data: List<BaseNode>, position: Int): Int {
        return when (data[position]) {
            is TopDecoration -> TYPE_TOP
            is BottomDecoration -> TYPE_BOTTOM
            is DataModel -> TYPE_TITLE
            is ChildModel -> TYPE_CHILD
            else -> -1
        }
    }

    companion object {
        const val TYPE_TOP = 0
        const val TYPE_BOTTOM = 1
        const val TYPE_TITLE = 2
        const val TYPE_CHILD = 3
    }
}